/*

* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Smart-Shop开源商城系统/ Java商城-首选电商平台系统 请务必保留此注释头信息
* |     开源地址: https://gitee.com/ningbo-qishan/gruul-mall
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     可正常分享和学习源码,未经授权 不可商用！
* |     商业版中台购买/开源版商业授权 联系技术客服
* |     官网:  https://www.73app.cn/
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Copyright (c) 2016-2999 宁波启山智软科技有限公司
* |     版权所有 ,侵权必究！
* ------------------------------------------------------------------------

*/
package com.medusa.gruul.account.web.controller.api;

import com.medusa.gruul.account.model.dto.UpdateApiMemberExpireTimeDto;
import com.medusa.gruul.account.model.dto.UpdateApiMemberExpireTimePageDto;
import com.medusa.gruul.account.model.dto.UpgradeApiMemberRankDto;
import com.medusa.gruul.account.model.dto.UpgradeApiMemberRankPageDto;
import com.medusa.gruul.account.model.vo.ApiMemberCardInfoVo;
import com.medusa.gruul.account.model.vo.MemberCardUpgradeVo;
import com.medusa.gruul.account.service.IApiMemberInfoService;
import com.medusa.gruul.common.core.util.Result;
import com.medusa.gruul.payment.api.model.dto.PayResultDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 会员信息功能相关小程序端
 * @Author: zhaokw
 * @Date: 2020/5/30 12:58
 **/
@RestController
@RequestMapping("/api")
@Api(tags = "会员信息相关功能小程序端")
public class ApiMemberInfoController {

    @Autowired
    private IApiMemberInfoService apiMemberInfoService;

    /**
     * 会员信息列表主页小程序端
     *
     * @param
     * @param
     * @return
     */
    @GetMapping("/getMemberInfo")
    @ApiOperation(value = "小程序端会员信息列表")
    public Result<List<ApiMemberCardInfoVo>> getMemberInfo() {
        List<ApiMemberCardInfoVo> apiMemberCardInfoVos = apiMemberInfoService.getMemberInfo();
        return Result.ok(apiMemberCardInfoVos);
    }

    /**
     * 小程序端更新会员的到期日，会员续费
     *
     * @param
     * @return
     */
    @PostMapping("/updateMemberExpireTime")
    @ApiOperation(value = "小程序端更新会员的到期日，会员续费")
    public Result updateMemberExpireTime(@RequestBody @Validated UpdateApiMemberExpireTimeDto updateApiMemberExpireTimeDto) {
        PayResultDto payResultDto = apiMemberInfoService.updateMemberExpireTime(updateApiMemberExpireTimeDto);
        return Result.ok(payResultDto);
    }
    @PostMapping("/updateMemberExpireTime/page")
    public Result<?> updateMemberExpireTimePage(@RequestBody @Validated UpdateApiMemberExpireTimePageDto memberExpire) {
        return Result.ok(
                apiMemberInfoService.updateMemberExpireTimePage(memberExpire)
        );
    }
    /**
     * 小程序端升级会员等级界面，暂考虑该用户所持有的会员卡和后台设置的种类一致，不一致则提示开通，跳转到开通界面
     *
     * @param
     * @return
     */
    @GetMapping("/getMemberCardUpgrade")
    @ApiOperation(value = "小程序端升级会员界面")
    public Result<MemberCardUpgradeVo> getMemberCardUpgrade(
            @ApiParam(name = "memberId", value = "会员id") @RequestParam(required = false) String memberId
    ) {
        MemberCardUpgradeVo memberCardUpgrade = apiMemberInfoService.getMemberCardUpgrade(memberId);
        return Result.ok(memberCardUpgrade);
    }

    /**
     * 小程序端升级会员等级
     *
     * @param
     * @return
     */
    @PostMapping("/upgradeMemberRank")
    @ApiOperation(value = "小程序端升级会员等级")
    public Result upgradeMemberRank(@RequestBody @Validated UpgradeApiMemberRankDto upgradeApiMemberRankDto) {
        PayResultDto payResultDto = apiMemberInfoService.upgradeMemberRank(upgradeApiMemberRankDto);
        return Result.ok(payResultDto);
    }

    @PostMapping("/upgradeMemberRank/page")
    @ApiOperation(value = "小程序端升级会员等级")
    public Result<?> upgradeMemberRankPage(@RequestBody @Validated UpgradeApiMemberRankPageDto updateMemberRankPage) {
        return Result.ok(
                apiMemberInfoService.upgradeMemberRankPage(updateMemberRankPage)
        );
    }

}

